# coding=utf-8
import sys, os
from typing import NewType

BASE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_PATH)  # 项目目录
import pymysql


class mysql(object):
    def __init__(self, username="", password="", database="yisoo_rs", host=""):
        self.conn_conf = {"username": username, "password": password, "database": database, "host": host,
                          "charset": 'utf8'}
        self.db = pymysql.connect(
            user=self.conn_conf["username"],
            password=self.conn_conf["password"],
            host=self.conn_conf["host"],
            database=self.conn_conf["database"],
            charset=self.conn_conf["charset"]
        )
        # 修改默认游标格式
        self.cursor = self.db.cursor(pymysql.cursors.DictCursor)
        effect_row = self.cursor.execute("select * from movies_star")
        print(effect_row)
        print(self.cursor.fetchone())
        # self.cursor.commit()

    def create(self):
        pass

    def retrieve(self):
        pass

    def update(self):
        pass

    def delete(self):
        pass

    def __del__(self):
        if self.db:
            self.db.close()
        if self.cursor:
            self.cursor.close()


if __name__ == "__main__":
    db = mysql()
